import * as bm from "/js/baseModule.js";

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        let that = this;
        this.initData();
    }
    initTpl() {
        let that = this;
        new Vue({
            el: "#selProv_vue",
            data: { citys: that.nation },
            methods: {
                clickProv: function (prov, e) {
                    // 如果是直辖市
                    if (prov.provCity) {
                        globalData.selPos.city = prov.name;
                        globalData.selPos.city_id =  prov.adcode;
                        globalData.selPos.prov = prov.name;
                        globalData.selPos.prov_id = prov.adcode;
                        funs.getModuleFuns('modules/project/ProjectList.js',function (mod) {
                            mod.setCity(prov.name);
                        });
                        that._evt_goback();
                        //正常的省
                    } else {
                        location.hash = 'project/SelProvDemand/SelCityDemand';
                        funs.swipeModule('modules/project/SelCityDemand.js','100%','left',function (mod) {
                            mod.initTpl(prov);
                        },true);
                    }
                }
            }
        })

    }
    //处理初始数据
    initData() {
        let that = this;
        let hasChoosedArea = globalData.pack.area_id;
        // 获取全国城市列表，然后把已经选择了的城市做标记
        $.getJSON('/prov_city.json', function (json) {
            that.nation = json;

            for (let i = 0, len = that.nation.length; i < len; i++) {
                let jLen = that.nation[i].subs.length;

                // 如果只有一个城市的省（也就是直辖市），直接处理
                if (jLen == 1) {
                    that.nation[i].provCity = true;
                } else {
                    //不是直辖市
                    that.nation[i].provCity = false;
                }
            }
            that.initTpl();
        });
    }
}
